// c:\Users\Administrator\Desktop\hahah\toutiao\pages\xiangqing\xiangqing.js
Page({
  data: {
    vote_option: '',
    xiangqing:'',
    id:'',
    renwuid:'',
    dameinv:[],
    a:''
    ,
    user:''
  },
  onLoad: function (e) {
    this.setData({
      renwuid:e.id
    })
  },
  onShow:function(){
    const user=tt.getStorageSync('meinv')

    this.setData({
      user:user
    })
    this.chuio()
  },
  chuio(){
  tt.request({
    url:'https://ceshi666.yxbnet.cn/api/Rota/modulardetails',
    data:{
           id:this.data.renwuid,
           userid:this.data.user.id
    },
    method:'POST',
    success:res=>{
      console.log(111,res.data.data);
      this.setData({
       xiangqing:res.data.data,
       id:this.data.renwuid,
       dameinv:res.data.data.vote_option,
       a:res.data.data,
       renwuid:this.data.renwuid
      })
    }
  })
  },
  changetype(type) {
    var _this=this
    console.log(type);
    this.setData({
      vote_option: type.currentTarget.dataset.type
    })


// 选择 
tt.request({
  url:'https://ceshi666.yxbnet.cn/api/Rota/addvote',
  data:{
    listid:this.data.id,
    userid:this.data.user.id,
    option:this.data.vote_option
  },
  method:'POST',
  success:res=>{
    console.log(777,res);
    if(res.data.code==1){
      tt.showToast({
        title:'投票成功'
      })
      _this.chuio()
    }else{
      tt.showToast({
        title:'您已进行投票'
      })
    }
    
  }
})


  },

  // 上下
  shangxia(e){
    tt.request({
      url:'https://ceshi666.yxbnet.cn/api/Rota/limit',
      data:{
        userid:this.data.user.id,
        id:this.data.id,
        type:e.currentTarget.dataset.lala
      },
      method:'POST',
      success:res=>{
        tt.request({
          url:'https://ceshi666.yxbnet.cn/api/Rota/modulardetails',
          data:{
                 id:res.data.data.id,
                 userid:this.data.user.id
          },
          method:'POST',
          success:res=>{
            console.log(888,res);
            this.setData({
             xiangqing:res.data.data,
             id:this.data.renwuid,
             dameinv:res.data.data.vote_option,
             a:res.data.data,
             renwuid:this.data.renwuid
            })
          }
        })
        this.setData({
          renwuid:res.data.data.id
        })
        if(res.data.code==0){
           tt.showToast({
             title:res.data.msg
           })
        }
        this.setData({
          xiangqing:res.data.data,
          id:res.data.data.id
        })
      }
    })
  },


 
  // 分享
  onShareAppMessage(res) {
    const xiaojiang=this.data.xiangqing;
    console.log(676,this.data.xiangqing);
    const oo=this.data.renwuid
    return {
      desc:xiaojiang.coun,
      title:xiaojiang.vato_name,
      imageUrl:xiaojiang.vote_image,
      path: '/pages/jieguo/jieguo?id='+oo
    }
  },




  // 广告
  adloadhandler(e) {
    console.log("广告加载成功");
  },
  aderrorhandler(e) {
    console.log("广告加载失败", e);
    tt.showToast({
      title: "广告加载失败" + e.errMsg,
      icon: "fail",
    });
  },
  adclosehandler(e) {
    console.log("广告关闭");
  },
})